/**
 * Copyright &copy; 2012-2015  All rights reserved.
 */
package com.smartwork.modules.sys.service;

import com.google.common.collect.Maps;
import com.smartwork.common.persistence.Page;
import com.smartwork.common.service.CrudService;
import com.smartwork.modules.sys.dao.ClientVersionDao;
import com.smartwork.modules.sys.entity.ClientVersion;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Map;


import java.util.List;

/**
 * 客户端版本管理Service
 * @author Albertyan
 * @version 2015-12-25
 */
@Service
@Transactional(readOnly = true)
public class ClientVersionService extends CrudService<ClientVersionDao, ClientVersion> {

	public ClientVersion get(String id) {
		return super.get(id);
	}
	
	public List<ClientVersion> findList(ClientVersion clientVersion) {
		return super.findList(clientVersion);
	}

    public Page<ClientVersion> findPage(Page<ClientVersion> page, ClientVersion clientVersion) {
        return super.findPage(page, clientVersion);
    }
	
	@Transactional(readOnly = false)
	public void save(ClientVersion clientVersion) {
		super.save(clientVersion);
	}
	
	@Transactional(readOnly = false)
	public void delete(ClientVersion clientVersion) {
		super.delete(clientVersion);
	}

    public Map<String, Object> getMaxVersion(ClientVersion clientVersion) {
        ClientVersion version = dao.getMaxVersion(clientVersion);
        Integer upFalg ;
        if(version.getBuildNo().compareTo(clientVersion.getBuildNo()) == 0){
            // 当前版本为最新版本
            upFalg = 1;
        } else if(version.getLowBuildNo() > clientVersion.getBuildNo()){
            // 当前版本不是最新版本,需要强制更新
            upFalg = 3;
        } else {
            // 当前版本不是最新版本
            upFalg = 2;
        }
        Map<String, Object> resultMap = Maps.newHashMap();
        resultMap.put("upFalg", upFalg);
        resultMap.put("version", version);
        return resultMap;
    }
	
}